package com.sigmazero13.MKDummy.utils;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.sigmazero13.MKDummy.R;
import com.sigmazero13.MKDummy.models.ReferenceCard;

public class ReferenceCardListAdapter extends ArrayAdapter<ReferenceCard> {
	private List<ReferenceCard> cards;
	
	public ReferenceCardListAdapter(Context context, int textViewResourceId, List<ReferenceCard> cards) {
		super(context, textViewResourceId, cards);
		this.cards = cards;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi;
			vi = LayoutInflater.from(getContext());
			v = vi.inflate(R.layout.list_item, null);
		}
		
		ReferenceCard card = cards.get(position);
		
		if (card != null) {
			TextView tt = (TextView)v.findViewById(R.id.list_item_text);
			if (tt != null) {
				tt.setText(card.getTitle());
			}
		}
		
		return v;
	}
}
